<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-1.11.0.min.js"></script>
</head>
<body>

    <form>
        <input type="hidden" name="id" id="id">
        姓名：<input type="text" id="name" name="name"> <br>
        性别：<input type="text" id="gender" name="gender"> <br>
        年龄：<input type="text" id="age" name="age"> <br>
        地址：<input type="text" id="address" name="address"> <br>
        qq号：<input type="text" id="qq" name="qq" > <br>
        邮箱：<input type="text" id="email" name="email" > <br>
        生日：<input type="text" id="bir"  name="bir"> <br>
    </form>

    <input type="button" value="更新" id="update">
</body>
<script>

    let queryString = location.search; //?id=23
    let id = queryString.split("=")[1]

    //进入页面，根据当前用户的id查询用户对象，回显数据
    let url = "/anli/user?action=findOne"
    let params = {id:id}
    $.get(url,params,function (user){
        $("#name").val(user.name);
        $("#gender").val(user.gender);
        $("#age").val(user.age);
        $("#address").val(user.address);
        $("#qq").val(user.qq);
        $("#email").val(user.email);
        $("#bir").val(user.bir);
    },"json");


    //给更新按钮绑定单击事件
    $("#update").click(function (){
        //绑定id
        $("#id").val(id);
        //获取用户填充的数据： name=zs&age=18&...
        let params = $("form").serialize();
        let url = "/anli/user?action=update"
        $.post(url,params,function (data){
            if (data === "true"){
                location.href = "user.html"
            }else{
                alert("更新失败")
            }
        },"text");
    });
</script>

</html>